From bd0b8968b0ea8f220a7da1ddab7f74d53dd019e4 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Fri, 22 Oct 2021 01:44:15 +0200
Subject: [PATCH 1/7] export MACHINE_ARCH instead of DPKG_ARCH

This allows us to do machine checks in hooks in a way that is
independent of dpkg.
---
 hooks/thermal     | 4 ++--
 init              | 6 +++---
 initramfs-tools.7 | 6 +++---
 mkinitramfs       | 6 +++---
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/hooks/thermal b/hooks/thermal
index 0a42c12..b318e9f 100755
--- a/hooks/thermal
+++ b/hooks/thermal
@@ -19,9 +19,9 @@ esac
 
 . /usr/share/initramfs-tools/hook-functions
 
-case "$DPKG_ARCH" in
+case "$MACHINE_ARCH" in
 # copy the right modules
-powerpc|ppc64)
+ppc|ppc64)
 
 	# Only G5 Mac machines need to load
 	# windfarm_core or one of the windfarm_pm* modules.
diff --git a/init b/init
index 43eb349..99c842f 100755
--- a/init
+++ b/init
@@ -44,8 +44,8 @@ mount -t devtmpfs -o nosuid,mode=0755 udev /dev
 mkdir /dev/pts
 mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
 
-# Export the dpkg architecture
-export DPKG_ARCH=
+# Export the machine architecture
+export MACHINE_ARCH=
 . /conf/arch.conf
 
 # Set modprobe env
@@ -298,7 +298,7 @@ maybe_break init
 # (keep init, rootmnt, drop_caps)
 unset debug
 unset MODPROBE_OPTIONS
-unset DPKG_ARCH
+unset MACHINE_ARCH
 unset ROOTFLAGS
 unset ROOTFSTYPE
 unset ROOTDELAY
diff --git a/initramfs-tools.7 b/initramfs-tools.7
index 2d5d2d2..242541b 100644
--- a/initramfs-tools.7
+++ b/initramfs-tools.7
@@ -1,4 +1,4 @@
-.TH INITRAMFS-TOOLS 7  "2018/07/18" "initramfs\-tools" "Linux Programmer's Manual"
+W.TH INITRAMFS-TOOLS 7  "2018/07/18" "initramfs\-tools" "Linux Programmer's Manual"
 
 .SH NAME
 initramfs-tools \- an introduction to writing scripts for mkinitramfs
@@ -309,7 +309,7 @@ is the path of the used initramfs-tools configurations.
 \fB\fI DESTDIR
 is the root path of the newly build initramfs.
 .TP
-\fB\fI DPKG_ARCH
+\fB\fI MACHINE_ARCH
 allows arch specific hook additions.
 .TP
 \fB\fI verbose
@@ -574,7 +574,7 @@ corresponds to the rootdelay, rootflags, rootfstype or ip boot option.
 Use of ROOTDELAY is deprecated; you should implement a \fIlocal-block\fR
 boot script rather than delaying or polling.
 .TP
-\fB\fI DPKG_ARCH
+\fB\fI MACHINE_ARCH
 allows arch specific boot actions.
 .TP
 \fB\fI blacklist, panic, quiet, resume, noresume, resume_offset
diff --git a/mkinitramfs b/mkinitramfs
index df1b940..0f7b81e 100755
--- a/mkinitramfs
+++ b/mkinitramfs
@@ -284,7 +284,7 @@ __TMPCPIOGZ="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-OL_XXXXXX")" || exit 1
 __TMPMAINCPIO="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-MAIN_XXXXXX")" || exit 1
 __TMPEARLYCPIO="$(mktemp "${TMPDIR:-/var/tmp}/mkinitramfs-FW_XXXXXX")" || exit 1
 
-DPKG_ARCH=$(dpkg --print-architecture)
+MACHINE_ARCH=$(uname -m)
 
 # Export environment for hook scripts.
 #
@@ -292,7 +292,7 @@ export MODULESDIR
 export version
 export CONFDIR
 export DESTDIR
-export DPKG_ARCH
+export MACHINE_ARCH
 export verbose
 export KEYMAP
 export MODULES
@@ -379,7 +379,7 @@ for b in $(cd "${CONFDIR}/scripts" && find . -maxdepth 2 -name '.?*' -prune -o \
 	cp -p "${CONFDIR}/scripts/${b}" "${DESTDIR}/scripts/$(dirname "${b}")/"
 done
 
-echo "DPKG_ARCH=${DPKG_ARCH}" > "${DESTDIR}/conf/arch.conf"
+echo "MACHINE_ARCH=${MACHINE_ARCH}" > "${DESTDIR}/conf/arch.conf"
 cp -p "${CONFDIR}/initramfs.conf" "${DESTDIR}/conf"
 for i in ${EXTRA_CONF}; do
 	copy_file config "${i}" /conf/conf.d
-- 
2.37.1

